package com.jsp.before.servlet; /**
 * @author wzm
 * @create 2023-03-08 16:09
 */

import com.jsp.before.entity.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/sear")
public class SearServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置请求编码
        //获取请求参数
        //调用service查询数据  模拟数据
        List<Student> studentList = new ArrayList<>();
        for(int i = 0;i < 10; i++){
            int t =i+1;
            studentList.add(new Student(t,"name"+t,18+t,"phone"+t));
        }

        //将结果保存到域对象中
        request.setAttribute("stuList",studentList);
        //请求转发到显示数据的页面
        request.getRequestDispatcher("/studentlist.jsp").forward(request,response);

    }
}
